﻿/*----------------------------------------------------------------
  //Copyright (C) 2012 赵国伟
  //文件功能描述：个人中心登录后台程序
  //创建人：赵国伟
  //生成时间：2012/03/17 16:15:00
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Shopping.Common;
using Shopping.Model;
using Shopping.BLL;

public partial class Home_Login : BasePage
{
    protected string BackUrl = ""; //返回地址；
    protected bool IsRember = true; //是否记住登录名
    protected bool IsAutoLogin = false; //是否自动登录；
    protected string UserName = ""; //登录用户名；

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            BackUrl = Utility.G("BackUrl");
          
            UsersManage bllUser = new UsersManage();
            if (bllUser.IsLogin())
            {
                Response.Redirect("/home/default.aspx");
                Response.End();
            }
            string s = Utility.GetCookies("IsRemberUserName");
            if (Utility.GetCookies("IsRemberUserName") != "")
                IsRember = Utility.Cast2bool(Utility.GetCookies("IsRemberUserName"));
            IsAutoLogin = Utility.Cast2bool(Utility.GetCookies("IsAutologin"));
            UserName = Utility.GetCookies("tmpUserName");
            var UserPwd = Utility.GetCookies("tmpUserPwd");
            if (IsAutoLogin)  //设置自动登录；
            {
                if (bllUser.IsCanLogin(UserName, Utility.MD5(UserPwd)).IsSucc)
                {
                    Users u = bllUser.GetUserInfoByName(UserName);
                    bllUser.Login(u);
                    if (string.IsNullOrEmpty(BackUrl))
                        Response.Redirect("/Home/default.aspx");
                    else
                        Response.Redirect(BackUrl);
                }
            }

        }
    }
}